<template>
<img src="../../assets/youxue.jpg" alt="">
    <div>
        账号：<input type="text" name="1" id="1" v-model="username" @blur="checkusername"><br>
        密码：<input type="password" name="" id="" v-model="password" @blur="checkpassword"><br>
        <button @click="register">注册</button>
    </div>
</template>

<script>
import {get, post} from '../../utils/request'
export default {
    name:'rigister',
    data(){
        return{
            username:'',
            password:'',
        }
    },
    methods:{
        checkusername(){
            get('http://127.0.0.1:8000/user/check/username/'+ this.username +'/').then(res=>{
                if(res.data.code ==200){
                //    alert(res.data.msg)                    
                }else{
                    // alert(res.data.msg)
                }
 
            }).catch(err=>{
                console.log(err)
            })
        },
        checkpassword(){
            post('http://127.0.0.1:8000/user/check/password/',{password:this.password}).then(res=>{
                if(res.data.code ==200){
                //    alert(res.data.msg)                    
                }else{
                    // alert(res.data.msg)
                }
 
            }).catch(err=>{
                console.log(err)
            })
        },
        register(){
            post('http://127.0.0.1:8000/user/register/',{password:this.password,username:this.username}).then(res=>{
                if(res.data.code==200){
                    alert(res.data.msg)
                    this.$router.push('/Login')
                }else{
                    alert(res.data.msg)
                }
            }).catch(err=>{
                console.log(err)
            })
        }
    }
}
</script>

<style>

</style>